package com.snowj.apaas.repository.auto;

import static com.snowj.apaas.repository.auto.UsersDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.snowj.apaas.domain.auto.Users;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.insert.render.MultiRowInsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface UsersMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.245849+08:00", comments="Source Table: users")
    BasicColumn[] selectList = BasicColumn.columnList(username, realName, password, enabled, email, createdBy, createdDate, lastModifiedBy, lastModifiedDate, lastModifiedIp, entryDate, leaveDate, avatar);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.238173+08:00", comments="Source Table: users")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.239241+08:00", comments="Source Table: users")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.239627+08:00", comments="Source Table: users")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<Users> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.240182+08:00", comments="Source Table: users")
    @InsertProvider(type=SqlProviderAdapter.class, method="insertMultiple")
    int insertMultiple(MultiRowInsertStatementProvider<Users> multipleInsertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.240619+08:00", comments="Source Table: users")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("UsersResult")
    Optional<Users> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.241011+08:00", comments="Source Table: users")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="UsersResult", value = {
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIT),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="created_by", property="createdBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="created_date", property="createdDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="last_modified_by", property="lastModifiedBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="last_modified_date", property="lastModifiedDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="last_modified_ip", property="lastModifiedIp", jdbcType=JdbcType.VARCHAR),
        @Result(column="entry_date", property="entryDate", jdbcType=JdbcType.DATE),
        @Result(column="leave_date", property="leaveDate", jdbcType=JdbcType.DATE),
        @Result(column="avatar", property="avatar", jdbcType=JdbcType.VARCHAR)
    })
    List<Users> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.242361+08:00", comments="Source Table: users")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.242646+08:00", comments="Source Table: users")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.242935+08:00", comments="Source Table: users")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.243253+08:00", comments="Source Table: users")
    default int deleteByPrimaryKey(String username_) {
        return delete(c -> 
            c.where(username, isEqualTo(username_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.24359+08:00", comments="Source Table: users")
    default int insert(Users record) {
        return MyBatis3Utils.insert(this::insert, record, users, c ->
            c.map(username).toProperty("username")
            .map(realName).toProperty("realName")
            .map(password).toProperty("password")
            .map(enabled).toProperty("enabled")
            .map(email).toProperty("email")
            .map(createdBy).toProperty("createdBy")
            .map(createdDate).toProperty("createdDate")
            .map(lastModifiedBy).toProperty("lastModifiedBy")
            .map(lastModifiedDate).toProperty("lastModifiedDate")
            .map(lastModifiedIp).toProperty("lastModifiedIp")
            .map(entryDate).toProperty("entryDate")
            .map(leaveDate).toProperty("leaveDate")
            .map(avatar).toProperty("avatar")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.244485+08:00", comments="Source Table: users")
    default int insertMultiple(Collection<Users> records) {
        return MyBatis3Utils.insertMultiple(this::insertMultiple, records, users, c ->
            c.map(username).toProperty("username")
            .map(realName).toProperty("realName")
            .map(password).toProperty("password")
            .map(enabled).toProperty("enabled")
            .map(email).toProperty("email")
            .map(createdBy).toProperty("createdBy")
            .map(createdDate).toProperty("createdDate")
            .map(lastModifiedBy).toProperty("lastModifiedBy")
            .map(lastModifiedDate).toProperty("lastModifiedDate")
            .map(lastModifiedIp).toProperty("lastModifiedIp")
            .map(entryDate).toProperty("entryDate")
            .map(leaveDate).toProperty("leaveDate")
            .map(avatar).toProperty("avatar")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.244877+08:00", comments="Source Table: users")
    default int insertSelective(Users record) {
        return MyBatis3Utils.insert(this::insert, record, users, c ->
            c.map(username).toPropertyWhenPresent("username", record::getUsername)
            .map(realName).toPropertyWhenPresent("realName", record::getRealName)
            .map(password).toPropertyWhenPresent("password", record::getPassword)
            .map(enabled).toPropertyWhenPresent("enabled", record::getEnabled)
            .map(email).toPropertyWhenPresent("email", record::getEmail)
            .map(createdBy).toPropertyWhenPresent("createdBy", record::getCreatedBy)
            .map(createdDate).toPropertyWhenPresent("createdDate", record::getCreatedDate)
            .map(lastModifiedBy).toPropertyWhenPresent("lastModifiedBy", record::getLastModifiedBy)
            .map(lastModifiedDate).toPropertyWhenPresent("lastModifiedDate", record::getLastModifiedDate)
            .map(lastModifiedIp).toPropertyWhenPresent("lastModifiedIp", record::getLastModifiedIp)
            .map(entryDate).toPropertyWhenPresent("entryDate", record::getEntryDate)
            .map(leaveDate).toPropertyWhenPresent("leaveDate", record::getLeaveDate)
            .map(avatar).toPropertyWhenPresent("avatar", record::getAvatar)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.246787+08:00", comments="Source Table: users")
    default Optional<Users> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.247139+08:00", comments="Source Table: users")
    default List<Users> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.247487+08:00", comments="Source Table: users")
    default List<Users> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.247843+08:00", comments="Source Table: users")
    default Optional<Users> selectByPrimaryKey(String username_) {
        return selectOne(c ->
            c.where(username, isEqualTo(username_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.248121+08:00", comments="Source Table: users")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, users, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.248404+08:00", comments="Source Table: users")
    static UpdateDSL<UpdateModel> updateAllColumns(Users record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(username).equalTo(record::getUsername)
                .set(realName).equalTo(record::getRealName)
                .set(password).equalTo(record::getPassword)
                .set(enabled).equalTo(record::getEnabled)
                .set(email).equalTo(record::getEmail)
                .set(createdBy).equalTo(record::getCreatedBy)
                .set(createdDate).equalTo(record::getCreatedDate)
                .set(lastModifiedBy).equalTo(record::getLastModifiedBy)
                .set(lastModifiedDate).equalTo(record::getLastModifiedDate)
                .set(lastModifiedIp).equalTo(record::getLastModifiedIp)
                .set(entryDate).equalTo(record::getEntryDate)
                .set(leaveDate).equalTo(record::getLeaveDate)
                .set(avatar).equalTo(record::getAvatar);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.24878+08:00", comments="Source Table: users")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Users record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(username).equalToWhenPresent(record::getUsername)
                .set(realName).equalToWhenPresent(record::getRealName)
                .set(password).equalToWhenPresent(record::getPassword)
                .set(enabled).equalToWhenPresent(record::getEnabled)
                .set(email).equalToWhenPresent(record::getEmail)
                .set(createdBy).equalToWhenPresent(record::getCreatedBy)
                .set(createdDate).equalToWhenPresent(record::getCreatedDate)
                .set(lastModifiedBy).equalToWhenPresent(record::getLastModifiedBy)
                .set(lastModifiedDate).equalToWhenPresent(record::getLastModifiedDate)
                .set(lastModifiedIp).equalToWhenPresent(record::getLastModifiedIp)
                .set(entryDate).equalToWhenPresent(record::getEntryDate)
                .set(leaveDate).equalToWhenPresent(record::getLeaveDate)
                .set(avatar).equalToWhenPresent(record::getAvatar);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.249355+08:00", comments="Source Table: users")
    default int updateByPrimaryKey(Users record) {
        return update(c ->
            c.set(realName).equalTo(record::getRealName)
            .set(password).equalTo(record::getPassword)
            .set(enabled).equalTo(record::getEnabled)
            .set(email).equalTo(record::getEmail)
            .set(createdBy).equalTo(record::getCreatedBy)
            .set(createdDate).equalTo(record::getCreatedDate)
            .set(lastModifiedBy).equalTo(record::getLastModifiedBy)
            .set(lastModifiedDate).equalTo(record::getLastModifiedDate)
            .set(lastModifiedIp).equalTo(record::getLastModifiedIp)
            .set(entryDate).equalTo(record::getEntryDate)
            .set(leaveDate).equalTo(record::getLeaveDate)
            .set(avatar).equalTo(record::getAvatar)
            .where(username, isEqualTo(record::getUsername))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2021-01-10T12:57:45.249858+08:00", comments="Source Table: users")
    default int updateByPrimaryKeySelective(Users record) {
        return update(c ->
            c.set(realName).equalToWhenPresent(record::getRealName)
            .set(password).equalToWhenPresent(record::getPassword)
            .set(enabled).equalToWhenPresent(record::getEnabled)
            .set(email).equalToWhenPresent(record::getEmail)
            .set(createdBy).equalToWhenPresent(record::getCreatedBy)
            .set(createdDate).equalToWhenPresent(record::getCreatedDate)
            .set(lastModifiedBy).equalToWhenPresent(record::getLastModifiedBy)
            .set(lastModifiedDate).equalToWhenPresent(record::getLastModifiedDate)
            .set(lastModifiedIp).equalToWhenPresent(record::getLastModifiedIp)
            .set(entryDate).equalToWhenPresent(record::getEntryDate)
            .set(leaveDate).equalToWhenPresent(record::getLeaveDate)
            .set(avatar).equalToWhenPresent(record::getAvatar)
            .where(username, isEqualTo(record::getUsername))
        );
    }
}